package com.test.database;
import java.sql.*;


public class LinkMysql {
	 //驱动程序
    private String driverName = "com.mysql.cj.jdbc.Driver";
    //设置数据库连接URL
    private String url = "jdbc:mysql://localhost:3306/stest?useUnicode=true&characterEncoding=utf-8";
    private String user = "root";//数据库登录用户名
    private String password = "123456";//数据库登录密码 
	public String getDriverName() {
		return driverName;
	}
	public void setDriverName(String driverName) {
		this.driverName = driverName;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getUser() {
		return user;
	}
	public void setUser(String user) {
		this.user = user;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	 public Connection getConnection() {
	        try {
	            Class.forName(driverName);
	            return DriverManager.getConnection(url, user, password);
	        } catch (Exception e) {
	            //e.printStackTrace();
	            System.out.println("驱动异常");
	            return null;
	        }
	    }  



}

